package com.ibeeking.found.cop.b.rest.controller.v1;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ibeeking.found.cop.b.rest.service.IKfAccountService;
import com.ibeeking.found.cop.b.rest.service.IKfFriendsMessageService;
import com.ibeeking.found.cop.service.common.param.KfAccountParam;
import com.ibeeking.found.cop.service.common.query.KfAccountQuery;
import com.ibeeking.found.cop.service.common.query.KfFriendsMessagePageQuery;
import com.ibeeking.found.cop.service.common.vo.KfAccountVO;
import com.ibeeking.found.cop.service.common.vo.KfFriendsMessageVO;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName KfAccountController
 * @Description
 * @Author ibeeking
 * @Date 2021-06-02 18:15
 **/
@RestController
@RequestMapping("/b/kfAccount/v1")
public class KfAccountController {

    @Resource
    private IKfAccountService kfAccountServiceImpl;

    @Resource
    private IKfFriendsMessageService kfFriendsMessageServiceImpl;

    //客服账号
    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步客服账号列表")
    @PostMapping(value = "/syncKfAccountList")
    public Integer syncKfAccountList() {
        return kfAccountServiceImpl.syncKfAccountListFromWxCp();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客服账号列表")
    @PostMapping(value = "/list")
    public List<KfAccountVO> list(@RequestBody KfAccountQuery query) {
        return kfAccountServiceImpl.list(query);
    }

    @Log(logType = OperateLogTypeEnum.SAVE, describe = "添加客服账号")
    @PostMapping(value = "/add")
    public Boolean add(@RequestBody @Validated(BaseValidationGroup.Insert.class) KfAccountParam param) {
        return kfAccountServiceImpl.add(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改客服账号")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody @Validated(BaseValidationGroup.Update.class) KfAccountParam param) {
        return kfAccountServiceImpl.modify(param);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "修改是否启用")
    @GetMapping(value = "/changeStatus/{id}/{status}")
    public Boolean changeStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return kfAccountServiceImpl.changeStatus(id, status);
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查看客服账号详情")
    @GetMapping(value = "/view/{id}")
    public KfAccountVO view(@PathVariable("id") Long id) {
        return kfAccountServiceImpl.view(id);
    }

    @Log(logType = OperateLogTypeEnum.DEL, describe = "删除客服账号")
    @GetMapping(value = "/del/{id}")
    public Boolean del(@PathVariable("id") Long id) {
        return kfAccountServiceImpl.del(id);
    }

    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步客服账号")
    @PostMapping(value = "/syncKfAccountToWxCp/{id}")
    public Integer syncKfAccountToWxCp(@PathVariable("id") Long id) {
        return kfAccountServiceImpl.syncKfAccountToWxCp(id, false);
    }


    //客服接待消息互动同步
    @Log(logType = OperateLogTypeEnum.MODIFY, describe = "从企业微信同步客服接待消息列表")
    @PostMapping(value = "/syncKfFriendsMessageFromWxcp")
    public Integer syncKfFriendsMessageFromWxcp() {
        return kfFriendsMessageServiceImpl.syncKfFriendsMessageFromWx();
    }

    @Log(logType = OperateLogTypeEnum.QUERY, describe = "查询客服接待消息分页列表")
    @PostMapping(value = "/friendsMessagePageList")
    public Page<KfFriendsMessageVO> friendsMessagePageList(@RequestBody KfFriendsMessagePageQuery pageQuery) {
        return kfFriendsMessageServiceImpl.pageList(pageQuery);
    }

}
